/**
 * 设置header 会话控制
 */
var HEADER = {
	checkLogin : function() {
		var _ticket = $.cookie("TT_TOKEN");
		if (!_ticket) {
			return;
		}
		$
				.ajax({
					url : "http://localhost:8080/distribute-sso/user/token/"
							+ _ticket,
					dataType : "jsonp",
					type : "GET",
					success : function(data) {
						if (data.status == 200) {
							window.userInfo = data.data.username;
							window.loginTag=true;
							var username = data.data.username;
							var html = '<div style=""><button type="button" class=" center-block btn btn-default btn-lg logoutBtn">  <span class="glyphicon glyphicon-log-out" aria-hidden="true"></span> 注销 </button>'+'</div>';
							$(".temp_home").html(html);
							var html2 = '<a href="http://localhost:8080/distribute-portal/userhome/user-home.html"><i class="glyphicon glyphicon-user"></i>&nbsp;&nbsp;个人中心</a>';
							$(".login_message").html(html2);
							var html3 = '<li class="divider"></li><li><a class="logoutBtn" href="javascript:void(0)"><i class="glyphicon glyphicon-log-out"></i>&nbsp;&nbsp;注销</a></li>';
							$(".iconDrop").append(html3);
							/*alert("header in html:"+$(".logoutBtn").html());*/
							$(".logoutBtn").click(function () {
								$.ajax({
									url:'http://localhost:8080/distribute-sso/user/logout/'+$.cookie("TT_TOKEN"),
									dataType:'jsonp',
									success:function(data){
										/*alert(data.status);*/
										window.location.reload();
										/*window.location.href="http://localhost:8080/distribute-portal/index.html";*/
									},
								});
							});
						}
					}
				});
	},
};
$(function() {
	HEADER.checkLogin();
	/*alert("header out html:"+$(".logoutBtn").html());	*/

/*	$('.link-logout').click(function(){
		$.ajax({
			type:'GET',
			url : 'http://localhost:8080/distribute-sso/user/logout/' + $.cookie('TT_TOKEN'),
			dataType : 'jsonp',
			success : function(data) {
				alert("ok");
		   		 if(data.status == 200){
					window.location.href="http://localhost:8080/distribute-portal/index.html"; 
				window.location.reload();
				}
				
			}
		});
	});*/
});
